package com.railway.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.railway.bean.Admin;

/**
 * 用于过滤没登陆直接访问管理后台；跳转到登录页
 *
 */
@WebFilter("/12306/menu.jsp") 
public class LoginAdminFilter implements Filter{

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
HttpServletRequest req = (HttpServletRequest)request; 
		
		HttpServletResponse resp = (HttpServletResponse) response; 
		
		String uri = req.getRequestURI();
		if(req.getSession().getAttribute("loginAdmin") == null) {
			resp.sendRedirect("/12306/loginAdmin.html"); 
			return;
		}else {
			resp.sendRedirect("/12306/menu.jsp");
			chain.doFilter(request, response);
			return;
		}
	}

}
